/*
============================================================================
 Name        : nmsJpegMcuReader.h
 Author      : Jian
 Version     :
 Copyright   : base on http://ce.sharif.edu/~ahmadinejad/jpeg/
 Description : nmsJpegMcuReader.h - header file
============================================================================
*/

#ifndef NMSJPEGMCUREADER_H
#define NMSJPEGMCUREADER_H


#include "nmsJpegDefine.h"

#define __NMS_JPGE_MCU_BUF_LEN  256

/* Forward declaration */
struct __nms_jpeg ;

typedef struct __nms_jpeg_mcu {

    struct __nms_jpeg* jpg ;

    UINT8   fileBuf[__NMS_JPGE_MCU_BUF_LEN + 3] ;
    UINT32  bufBitLen ;
    int     curFilePos ;
    int     endBuf ;
    UINT32  readBitlen ;
    UINT16  curData ;
    UINT32  ffPos[3] ;
    int     preDC[__NMC_JPEG_COMP_ID_CR + 1] ;

    int     lineStartBitPos ;
    int     readDUCount ;
    int     x ;
    int     y ;

#ifdef __NMS_JPEG_DEBUG
    UINT32  testReadBitTotal ;
#endif
} nmsJpegMcu;


nmsJpegMcu* nmsMcuCreate(struct __nms_jpeg* jpg) ;

void nmsMcuDesctroy(nmsJpegMcu* mcu) ;

int nmsMcuInit(nmsJpegMcu* mcu, int startBitPos, int mcuVLineNo, int* curLineDc, int* nextLineDC) ;

int nmsMcuEatBits(nmsJpegMcu* mcu, int eatBitLen) ;

int nmsMcuReadNext(nmsJpegMcu* mcu) ;

int nmsMcuCmpXPixel(const nmsJpegMcu* mcu, int x) ;

int nmsMcuCmpYPixel(const nmsJpegMcu* mcu, int y) ;

int nmsMcuGetNextLineStartPos(nmsJpegMcu* mcu) ;

void nmsMcuInitCbCrIndexArray(struct __nms_jpeg* jpg) ;


#ifdef __NMS_JPEG_DEBUG
int nmsMcuTestReadDU(nmsJpegMcu* mcu, int compId, nmsMatrix* oriMatrix, nmsMatrix* dqtMatrix, nmsMatrix* idctMatrix) ;
void nmsMcuTestCheckMaker(nmsJpegMcu* mcu) ;
#endif

#endif  /* NMSJPEGMCUREADER_H */

/* End of File */
